// 
// Copyright (c) 2006-2009 Ben Motmans
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// Author(s):
//    Ben Motmans <ben.motmans@gmail.com>
//

using System;
using System.IO;
using System.Collections.Generic;

namespace Anculus.Core
{
	/// <summary>
	/// 
	/// </summary>
	public interface IConfigurationSection
	{
		/// <summary>
		/// Gets the name.
		/// </summary>
		/// <value>The name.</value>
		string Name { get; }

		/// <summary>
		/// Gets the <see cref="Anculus.Core.IConfigurationSection"/> with the specified name.
		/// </summary>
		/// <value></value>
		IConfigurationSection this[string name] { get; }

		/// <summary>
		/// Gets a value indicating whether this instance is the root section.
		/// </summary>
		/// <value><c>true</c> if this instance is root; otherwise, <c>false</c>.</value>
		bool IsRoot { get; }

		/// <summary>
		/// Gets the parent.
		/// </summary>
		/// <value>The parent.</value>
		IConfigurationSection Parent { get; }

		/// <summary>
		/// Gets a value indicating whether this instance is read only.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is read only; otherwise, <c>false</c>.
		/// </value>
		bool IsReadOnly { get; }

		/// <summary>
		/// Gets the section names.
		/// </summary>
		/// <value>The section names.</value>
		IEnumerable<string> SectionNames { get; }

		/// <summary>
		/// Gets the keys.
		/// </summary>
		/// <value>The keys.</value>
		IEnumerable<string> Keys { get; }

		/// <summary>
		/// Gets the sections.
		/// </summary>
		/// <value>The sections.</value>
		IEnumerable<IConfigurationSection> Sections { get; }

		/// <summary>
		/// Determines whether the specified name contains section.
		/// </summary>
		/// <param name="name">The name.</param>
		/// <returns>
		/// 	<c>true</c> if the specified name contains section; otherwise, <c>false</c>.
		/// </returns>
		bool ContainsSection (string name);

		/// <summary>
		/// Determines whether the specified name contains key.
		/// </summary>
		/// <param name="name">The name.</param>
		/// <returns>
		/// 	<c>true</c> if the specified name contains key; otherwise, <c>false</c>.
		/// </returns>
		bool ContainsKey (string name);

		/// <summary>
		/// Gets the number of items in this section.
		/// </summary>
		/// <value>The key count.</value>
		int KeyCount { get; }

		/// <summary>
		/// Gets number of child sections.
		/// </summary>
		/// <value>The section count.</value>
		int SectionCount { get; }

		/// <summary>
		/// Removes the section.
		/// </summary>
		/// <param name="name">The name of the section.</param>
		void RemoveSection (string name);

		/// <summary>
		/// Removes the specified item.
		/// </summary>
		/// <param name="name">The name of the item.</param>
		void Remove (string name);

		/// <summary>
		/// Get the <paramref name="T"/> value with the given name.
		/// </summary>
		/// <typeparam name="T">Primitive or serializable types.</typeparam>
		/// <param name="name">The name of the item.</param>
		/// <returns>The value if the item with the given name exists, default(T) otherwise</returns>
		T Get<T> (string name) where T : new ();

		/// <summary>
		/// Get the <see cref="System.Object"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the item.</param>
		/// <returns>The value if the item with the given name exists, <c>null</c> otherwise</returns>
		object GetObject (string name);
		
		ConfigurationObjectType GetObjectType (string name);
		
		/// <summary>
		/// Get the <see cref="System.Byte"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, 0x00 otherwise</returns>
		byte GetByte (string name);

		/// <summary>
		/// Get the <see cref="System.SByte"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, 0x00 otherwise</returns>
		sbyte GetSByte (string name);

		/// <summary>
		/// Get the <see cref="System.Boolean"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, false otherwise</returns>
		bool GetBool (string name);

		/// <summary>
		/// Get the <see cref="System.Int16"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, 0 otherwise</returns>
		short GetShort (string name);

		/// <summary>
		/// Get the <see cref="System.Int32"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, 0 otherwise</returns>
		int GetInt (string name);

		/// <summary>
		/// Get the <see cref="System.Int64"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, 0 otherwise</returns>
		long GetLong (string name);

		/// <summary>
		/// Get the <see cref="System.UInt16"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, 0 otherwise</returns>
		ushort GetUShort (string name);

		/// <summary>
		/// Get the <see cref="System.UInt32"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, 0 otherwise</returns>
		uint GetUInt (string name);

		/// <summary>
		/// Get the <see cref="System.UInt64"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, 0 otherwise</returns>
		ulong GetULong (string name);

		/// <summary>
		/// Get the <see cref="System.Float"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, 0.0F otherwise</returns>
		float GetFloat (string name);

		/// <summary>
		/// Get the <see cref="System.Double"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, 0.0 otherwise</returns>
		double GetDouble (string name);

		/// <summary>
		/// Get the <see cref="System.String"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <c>null</c> otherwise</returns>
		string GetString (string name);

		/// <summary>
		/// Get the <see cref="System.Char"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, '\0' otherwise</returns>
		char GetChar (string name);

		/// <summary>
		/// Get the <see cref="System.Decimal"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, 0 otherwise</returns>
		decimal GetDecimal (string name);

		/// <summary>
		/// Get the <see cref="System.DateTime"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, DateTime.MinValue otherwise</returns>
		DateTime GetDateTime (string name);

		/// <summary>
		/// Get an array of <paramref name="T"/> values with the given name.
		/// </summary>
		/// <typeparam name="T">Primitive or serializable types.</typeparam>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <c>null</c> otherwise</returns>
		T[] GetArray<T> (string name);

		/// <summary>
		/// Get a List of <paramref name="T"/> values with the given name.
		/// </summary>
		/// <typeparam name="T">Primitive or serializable types.</typeparam>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <c>null</c> otherwise</returns>
		IList<T> GetList<T> (string name);

		/// <summary>
		/// Get the <see cref="System.Byte"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		byte GetByte (string name, byte defaultValue);

		/// <summary>
		/// Get the <see cref="System.SByte"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		sbyte GetSByte (string name, sbyte defaultValue);

		/// <summary>
		/// Get the <see cref="System.Boolean"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		bool GetBool (string name, bool defaultValue);

		/// <summary>
		/// Get the <see cref="System.Int16"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		short GetShort (string name, short defaultValue);

		/// <summary>
		/// Get the <see cref="System.Int32"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		int GetInt (string name, int defaultValue);

		/// <summary>
		/// Get the <see cref="System.Int64"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		long GetLong (string name, long defaultValue);

		/// <summary>
		/// Get the <see cref="System.UInt16"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		ushort GetUShort (string name, ushort defaultValue);

		/// <summary>
		/// Get the <see cref="System.UInt32"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		uint GetUInt (string name, uint defaultValue);

		/// <summary>
		/// Get the <see cref="System.UInt64"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		ulong GetULong (string name, ulong defaultValue);

		/// <summary>
		/// Get the <see cref="System.Float"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		float GetFloat (string name, float defaultValue);

		/// <summary>
		/// Get the <see cref="System.Double"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		double GetDouble (string name, double defaultValue);

		/// <summary>
		/// Get the <see cref="System.String"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		string GetString (string name, string defaultValue);

		/// <summary>
		/// Get the <see cref="System.Char"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		char GetChar (string name, char defaultValue);

		/// <summary>
		/// Get the <see cref="System.Decimal"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		decimal GetDecimal (string name, decimal defaultValue);

		/// <summary>
		/// Get the <see cref="System.DateTime"/> value with the given name.
		/// </summary>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		DateTime GetDateTime (string name, DateTime defaultValue);

		/// <summary>
		/// Get an array of <paramref name="T"/> values with the given name.
		/// </summary>
		/// <typeparam name="T">Primitive or serializable types.</typeparam>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		T[] GetArray<T> (string name, T[] defaultValue);

		/// <summary>
		/// Get a List of <paramref name="T"/> values with the given name.
		/// </summary>
		/// <typeparam name="T">Primitive or serializable types.</typeparam>
		/// <param name="name">The name of the value.</param>
		/// <returns>The value if the item with the given name exists, <paramref name="defaultValue"/> otherwise</returns>
		IList<T> GetList<T> (string name, IList<T> defaultValue);
		
		void Set<T> (string name, T value);
		void SetObject (string name, object value);
		
		void SetByte (string name, byte value);
		void SetSByte (string name, sbyte value);
		void SetBool (string name, bool value);
		void SetShort (string name, short value);
		void SetInt (string name, int value);
		void SetLong (string name, long value);
		void SetUShort (string name, ushort value);
		void SetUInt (string name, uint value);
		void SetULong (string name, ulong value);
		void SetFloat (string name, float value);
		void SetDouble (string name, double value);
		void SetString (string name, string value);
		void SetChar (string name, char value);
		void SetDecimal (string name, decimal value);
		void SetDateTime (string name, DateTime value);
		void SetArray<T> (string name, T[] value);
		void SetList<T> (string name, IList<T> value);
	}
}